//
//  XDShareView.m
//  XDCommonApp
//
//  Created by XD-XY on 4/10/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "XDShareView.h"
#import "XDTools.h"
#import "XDHeader.h"
#import "UIView+category.h"
#import "UIButton+Category.h"
@implementation XDShareView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self makeView];
    }
    return self;
}

-(void)makeView
{
    
    if (IOS7){
        aheight = UI_SCREEN_HEIGHT;
    }else{
        aheight  = UI_MAINSCREEN_HEIGHT;
    }
    self.hview = [UIView initView:CGRectMake(0, 0, UI_SCREEN_WIDTH, aheight) bgcolor:[UIColor blackColor]];
    self.hview.alpha = 0.5;
    [self addSubview:_hview];
    
    self.Bgview = [UIView initView:CGRectMake(0, aheight, UI_SCREEN_WIDTH, 277/2.0f) bgcolor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"shareBg"]]];
    [self addSubview:_Bgview];
    
    self.xlBtn = [UIButton initButton:CGRectMake(8, 15, 302/2.0f, 84/2.0f) btnNorImage:[UIImage imageNamed:@"shareweibo"] btnPressBtn:[UIImage imageNamed:@"shareweibo"] btnTitle:nil titleColor:nil];
    [_xlBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    _xlBtn.tag = 1001;
    [_Bgview addSubview:_xlBtn];
    
    self.wxBtn = [UIButton initButton:CGRectMake(width_x(_xlBtn), _xlBtn.frame.origin.y, 302/2.0f, 84/2.0f) btnNorImage:[UIImage imageNamed:@"shareweixin"] btnPressBtn:[UIImage imageNamed:@"shareweixin"] btnTitle:nil titleColor:nil];
    [_wxBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDown];
    _wxBtn.tag = 1002;
    [_Bgview addSubview:_wxBtn];
    
    self.canelBtn = [UIButton initButton:CGRectMake(10, height_y(_xlBtn)+52/2.0f, 300, 40) btnNorImage:[UIImage imageNamed:@"shareCanel"] btnPressBtn:[UIImage imageNamed:@"shareCanel"] btnTitle:nil titleColor:nil titleFont:nil];
    [_canelBtn addTarget:self action:@selector(canelBtnClick) forControlEvents:UIControlEventTouchDown];
    [_Bgview addSubview:_canelBtn];
    
    self.hidden =YES;
}

-(void)setViewHidden
{
    [UIView animateKeyframesWithDuration:0.3 delay:0 options:0 animations:^{
//        _hview.hidden =YES;
        _Bgview.frame = CGRectMake(0, aheight, UI_SCREEN_WIDTH, 277/2.0f);
    } completion:^(BOOL finished) {
        self.hidden =YES;
    }];
}

-(void)setViewShow
{
    self.hidden =NO;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    _hview.hidden =NO;
    _Bgview.frame = CGRectMake(0, aheight-277/2.0f, UI_SCREEN_WIDTH, 277/2.0f);
    [UIView commitAnimations];
    
}

-(void)canelBtnClick
{
    [self setViewHidden];
}

#pragma mark ====================分享=========================
-(void)btnClick:(UIButton *)button
{
    [_delegate shareViewBtnCLick:button];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
